import api from '@/api'

export const validate = {
	is_mobile: str => {
		return /^1[3-9]\d{9}$/.test(str)
	},
	is_email: str => {
		return /^([a-zA-Z]|[0-9])(\w|\-|\.(?<!\.\.))+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/.test(str)
	},
}


export const track = params => {
	api.track({
		type: params.phone? 'phone':'service', //service 在线客服  phone 客服电话
		phone: params.phone || '', // 客服电话
		source: params.source, // 来源 firm 企业 askbuy 求购 supply 供应 goods 商品 shop 店铺
		source_id: params.id, // 来源记录ID
	})
}


export const consult = params => {
	uni.openCustomerServiceChat({
		extInfo: { url: 'https://work.weixin.qq.com/kfid/kfca5d6fb5f83413dc5' },
		corpId: 'ww25e38b0afbffa98d'
	})
	if(!params) return
	track(params)
}

export const makePhoneCall = params => {
	uni.makePhoneCall({phoneNumber: params.phone})
	if(!params) return
	track(params)
}